// Loesung_von_Aufgabe_4.7_5_periodische_Leiterschleife

// Für die Zeichnung der Leiterschleife gilt: 1 Pixel = 1 mm

float h = 300; // Höhe der Leiterschleife in mm
float b; // Breite der Leiterschleife in mm
float w = 2*PI/0.01; // w = Kreisfrequenz mit einer Periodendauer von 0.01 Sekunden
float v1; // Geschwindigkeit in mm/s
float v2; // Geschwindigkeit in m/s
float t; // Zeit in s
float U; // Spannung in V
float B = 1; // magnetische Flussdichte in T

void setup()
{
  size(400, 400);
}

void draw()
{
  background(255);

  // B-Feld
  noStroke();
  fill(155, 255, 150);
  rect(20, 25, 360, 350);
  fill(0, 150, 0);
  textSize(45);
  text("B", 80, 110);

  // Zeitschritt
  t = t + 0.00001; 

  // Leiterschleife (Die Breite b ändert sich periodisch zwischen 100 mm und 300 mm)
  b = 200 + 100 * sin(w*t); // b in mm
  v1 = 100 * w * cos(w*t); // v in mm/s
  v2 = v1/1000; // v in m/s (Umwandlung in m/s für die Berechnung der Spannung in Volt)

  stroke(0, 0, 255);
  strokeWeight(4);
  noFill();

  beginShape();
  vertex(50, 150);
  vertex(50, 50);
  vertex(50+b, 50);
  vertex(50+b, 350);
  vertex(50, 350);
  vertex(50, 250);
  endShape();

  ellipse(50, 155, 10, 10);
  ellipse(50, 245, 10, 10);

  // Induktionsspannung
  U = -B*h/1000*v2; // U in Volt (h wurde von mm in m umgerechnet)

  fill(0, 0, 255);
  textSize(24);
  text("U = " +(float)round(10*U)/10, 30, 210);
}